<template>
  <div>
    <el-dialog
      :title="title"
      width="45%"
      :visible="dialogOpen"
      @close="handleClose"
    >

      <el-form ref="skuDate" :model="skuDate">
        <el-form-item
          prop="skuName"
          label="商品类型名称"
        >
          <el-input v-model="skuDate.className" maxlength="10" show-word-limit />
        </el-form-item>
      </el-form>

      <el-row slot="footer" type="flex" justify="center" align="middle" class="dialog-footer">
        <el-button type="warning" plain @click="handleClose">取消</el-button>
        <el-button v-loading="loading" type="primary" @click="submit">确认</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { editSkuClass, addSkuClass } from '@/api/sku'
export default {
  props: {
    dialogOpen: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loading: false,
      skuDate: {
        className: ''
      }

    }
  },
  computed: {
    title() {
      return this.skuDate.classId ? '修改商品类型' : '新增商品类型'
    }
  },
  created() { },
  updated() { this.skuDate },
  methods: {
    handleClose() {
      this.$emit('update:dialogOpen', false)
      this.$refs.skuDate.resetFields()
      this.skuDate = {}
    },

    async submit() {
      try {
        await this.$refs.skuDate.validate()
        this.loading = true
        this.skuDate.classId ? await editSkuClass(this.skuDate) : await addSkuClass(this.skuDate)
        this.$message.success(this.skuDate.classId ? '修改成功' : ' 新增成功')
        this.handleClose()
        this.$emit('refreshlist')
      } catch (error) {
        console.log(error)
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form {
    padding: 0px 50px !important;
    width: 100%;
    .el-input {
     width: 396px !important;
    padding: 0 0 0 10px !important;
  }

  }
  ::v-deep label {
    font-weight: 400 !important;
  }

::v-deep .el-dialog__title {
    font-size: 16px !important;
    color: #333 !important;
    font-weight: 700;
}
.el-button--primary {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 80px!important;
    height: 36px;
    padding: 0;
    font-size: 14px;
    background: linear-gradient(135deg,#ff9743,#ff5e20)!important;
    border: none;
     margin-left: 50px !important;

  }
  .el-button--warning.is-plain {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 80px!important;
    height: 36px;
    padding: 0;
    background-color: #fbf4f0!important;
    border: none;
    color: #655b56!important;
      font-size: 14px;

  }

</style>
